#!/bin/bash

echo "🚀 安装 Nikou CLI 工具..."

# 检查 Node.js
if ! command -v node &> /dev/null; then
    echo "❌ 请先安装 Node.js"
    exit 1
fi

# 安装依赖
npm install

# 给路由器添加执行权限
chmod +x router.js

# 创建符号链接到系统路径
echo "📦 创建全局命令链接..."

# 创建 /usr/local/bin 下的符号链接
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROUTER_PATH="$SCRIPT_DIR/router.js"

sudo ln -sf "$ROUTER_PATH" /usr/local/bin/oc
sudo ln -sf "$ROUTER_PATH" /usr/local/bin/ob
sudo ln -sf "$ROUTER_PATH" /usr/local/bin/dops
sudo ln -sf "$ROUTER_PATH" /usr/local/bin/sonar

echo "✅ 安装完成！"
echo ""
echo "📋 可用命令:"
echo "  oc -n test-pod -p production"
echo "  ob -s my-service -e staging"
echo "  dops --help"
echo ""
echo "💡 每个命令都有独立的参数解析逻辑"